package com.codedancer.campus.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.codedancer.campus.common.core.BaseMapper;
import com.codedancer.campus.po.ChatMessage;
import com.codedancer.campus.po.ChatRoom;
import com.codedancer.campus.qo.chatMessage.ChatMessageSearchQo;
import com.codedancer.campus.qo.chatRoom.ChatRoomPageSearchQo;
import org.apache.ibatis.annotations.Param;

public interface ChatRoomMapper extends BaseMapper<ChatRoom> {

    /**
     * 分页查询聊天列表
     *
     * @param chatMessagePage
     * @param chatMessageSearchQo
     * @return
     */
    IPage<ChatRoom> pageList(Page<ChatMessage> chatMessagePage,
        @Param("chatMessageSearchQo") ChatMessageSearchQo chatMessageSearchQo);

    /**
     * 根据发送人和接收人获取聊天室
     * @param sendUserUuid
     * @param receiveUserUuid
     * @return
     */
    default ChatRoom selectChatRoomBySendUserUuidAndReceiveUserUuid(String sendUserUuid, String receiveUserUuid){
        LambdaQueryWrapper<ChatRoom> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ChatRoom::getHouseOwnerUuid, sendUserUuid).or()
            .eq(ChatRoom::getChatUserUuid, sendUserUuid);
        lambdaQueryWrapper.and((wrapper) -> {
            wrapper.eq(ChatRoom::getHouseOwnerUuid, receiveUserUuid).or()
                .eq(ChatRoom::getChatUserUuid, receiveUserUuid);
        });
        return selectOne(lambdaQueryWrapper);
    }

    /**
     * 分页查询聊天室
     * @param chatRoomPage
     * @param chatRoomPageSearchQo
     * @return
     */
    IPage<ChatRoom> page(Page<ChatRoom> chatRoomPage, @Param("chatRoomPageSearchQo") ChatRoomPageSearchQo chatRoomPageSearchQo);

    /**
     * 详情
     * @param uuid
     * @return
     */
    ChatRoom detail(String uuid);
}
